package ar.edu.unlam.tpfinal.model;

import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@MappedSuperclass
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class AbstractPersistentObject implements PersistentObject {

	protected Long oid;
	protected Long version;
	protected Timestamp creationTimestamp;
	protected Timestamp modificationTimestamp;
 
	public AbstractPersistentObject() {
		creationTimestamp = new Timestamp((new Date()).getTime());
		modificationTimestamp = new Timestamp((new Date()).getTime());
	}
	
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "OID", nullable = false, unique = true)
    public Long getOid() {
       return oid;
    }  
    public void setOid(Long newOID) {
       oid = newOID;
    }
 
    @Version
    @Column(name = "VERSION", nullable = false)
    public Long getVersion() {
        return version;
    }
    public void setVersion(Long version) {
        this.version = version;
    }
 
    @Column(name = "CREATION_TIMESTAMP", nullable = false)
    public Timestamp getCreationTimestamp() {
        return creationTimestamp;
    }
    public void setCreationTimestamp(Timestamp newCreationTimestamp) {
        creationTimestamp = newCreationTimestamp;
    }
 
    @Column(name = "MODIFICATION_TIMESTAMP", nullable = false)
    public Timestamp getModificationTimestamp() {
        return modificationTimestamp;
    }
    public void setModificationTimestamp(Timestamp newModificationTimestamp) {
        modificationTimestamp = newModificationTimestamp;
    }
	
}
